package com.hengtiansoft.productcrawl;

public class PriceBean implements Comparable<PriceBean>{
	private ProductBean product;
	
	private SellerBean seller;
	
	private double basePrice;
	
	private double tax;
	
	private double shipping;
	
	private double totalPrice;

	public PriceBean(ProductBean product, SellerBean seller, double basePrice,
			double tax, double shipping, double totalPrice) {
		super();
		this.product = product;
		this.seller = seller;
		this.basePrice = basePrice;
		this.tax = tax;
		this.shipping = shipping;
		this.totalPrice = totalPrice;
	}

	public ProductBean getProduct() {
		return product;
	}

	public void setProduct(ProductBean product) {
		this.product = product;
	}

	public SellerBean getSeller() {
		return seller;
	}

	public void setSeller(SellerBean seller) {
		this.seller = seller;
	}

	public double getBasePrice() {
		return basePrice;
	}

	public void setBasePrice(double basePrice) {
		this.basePrice = basePrice;
	}

	public double getTax() {
		return tax;
	}

	public void setTax(double tax) {
		this.tax = tax;
	}

	public double getShipping() {
		return shipping;
	}

	public void setShipping(double shipping) {
		this.shipping = shipping;
	}

	public double getTotalPrice() {
		return totalPrice;
	}

	public void setTotalPrice(double totalPrice) {
		this.totalPrice = totalPrice;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((product == null) ? 0 : product.hashCode());
		result = prime * result + ((seller == null) ? 0 : seller.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		PriceBean other = (PriceBean) obj;
		if (product == null) {
			if (other.product != null)
				return false;
		} else if (!product.equals(other.product))
			return false;
		if (seller == null) {
			if (other.seller != null)
				return false;
		} else if (!seller.equals(other.seller))
			return false;
		return true;
	}

	@Override
	public String toString() {
		return "PriceBean [product=" + product + ", seller=" + seller
				+ ", basePrice=" + basePrice + ", tax=" + tax + ", shipping="
				+ shipping + ", totalPrice=" + totalPrice + "]";
	}

	@Override
	public int compareTo(PriceBean o) {
		int skuComp = product.compareTo(o.getProduct());
		if (skuComp != 0) {
			return skuComp;
		} else {
			return seller.compareTo(o.getSeller());
		}
	}
	
	public String toCSV() {
		return product.getSku() + "," + product.getName() + ","
				+ seller.getUrl() + "," + basePrice + "," + tax + ","
				+ shipping + "," + totalPrice;
	}
}
